package com.tiger.web.controller.project;
import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.domain.model.LoginUser;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.utils.ServletUtils;
import com.tiger.common.utils.spring.SpringUtils;
import com.tiger.framework.web.service.TokenService;
import com.tiger.project.domain.ConstructionApply;
import com.tiger.project.domain.req.ConstructionApplyBack;
import com.tiger.project.service.IConstructionApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 【建设项目】Controller
 *
 * @author standard
 * @date 2022-09-16
 */
@Api(tags = "建设项目")
@RestController
@RequestMapping("/system/apply")
public class ConstructionApplyController extends BaseController {
    @Autowired
    private IConstructionApplyService constructionApplyService;

    /**
     * 查询【建设项目】列表
     */
    @ApiOperation(value = "查询【建设项目】列表")
    //@PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructionApply constructionApply) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        constructionApply.setCompanyId(loginUser.getUser().getDeptId());
        startPage();
        List<ConstructionApply> list = constructionApplyService.selectConstructionApplyList(constructionApply);
        return getDataTable(list);
    }



    /**
     * 获取【建设项目】详细信息
     */
    @ApiOperation(value = "获取【建设项目】列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(constructionApplyService.selectConstructionApplyById(id));
    }

    /**
     * 新增【建设项目】
     */
    @ApiOperation(value = "新增【建设项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:add')")
//    @Log(title = "新增【建设项目】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ConstructionApply constructionApply) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        constructionApply.setCompanyId(loginUser.getUser().getDeptId());
        constructionApply.setCreateById(loginUser.getUserId());
        constructionApply.setCreateByName(loginUser.getUsername());
        return toAjax(constructionApplyService.insertConstructionApply(constructionApply));
    }

    /**
     * 修改【建设项目】
     */
    @ApiOperation(value = "修改【建设项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:edit')")
//    @Log(title = "修改【建设项目】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ConstructionApply constructionApply) {
        return toAjax(constructionApplyService.updateConstructionApply(constructionApply));
    }

    /**
     * 删除【建设项目】
     */
    @ApiOperation(value = "删除【建设项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:remove')")
//    @Log(title = "删除【建设项目】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(constructionApplyService.deleteConstructionApplyByIds(ids));
    }

    @ApiOperation(value = "审核回调【建设项目】")
    //@PreAuthorize("@ss.hasPermi('system:apply:edit')")
//    @Log(title = "【建设项目】", businessType = BusinessType.UPDATE)
    @GetMapping("/callBack")
    public AjaxResult callBack(ConstructionApplyBack constructionApplyBack) {
        return toAjax(constructionApplyService.callBack(constructionApplyBack));
    }
}
